{extend name="adminblue/base" /}
{block name="resources"/}
<link rel="stylesheet" type="text/css" href="ADMIN_CSS/member_list.css" />
<style>
    .head-portrait{
        margin-top:15px;
    }
</style>
{/block}
{block name="main"}
<table class="mytable">
    <tr>
        <th width="20%" style="text-align: left;">
            <button class="btn-common-delete btn-small" onclick="batchDelete()" style="margin:0 5px 0 0 !important;">批量删除</button>
            <button class="btn-common btn-small" onclick="add_user()" style="margin:0 5px 0 0 !important;">添加会员</button>
        </th>

        <th>
            <select id="level_name" class="select-common">
                <option value ="-1">请选择会员等级</option>
                {volist name="level_list['data']" id="vo"}
                <option value ="{$vo.level_id}">{$vo.level_name}</option>
                {/volist}
            </select>
            <input type="text" id ='search_text' placeholder="输入手机号/邮箱/会员昵称" class="input-common" />
            <input type="button" onclick="searchData()" value="搜索" class="btn-common" />
            <input type="button" onclick="dataExcel()" value="导出数据" class="btn-common" />
        </th>
    </tr>
</table>
<table class="table-class">
    <thead>
    <tr align="center">
        <th><input type="checkbox" onclick="CheckAll(this)"></th>
        <th style="width: 30%;">会员</th>
        <th>会员等级</th>
        <th>积分</th>
        <th>账户余额</th>
        <th>注册&登录</th>
        <th>状态</th>
        <th style="width: 20%;">操作</th>
    </tr>
    </thead>
    <tbody id="productTbody"></tbody>
</table>

<!-- 余额调整 -->
<div class="modal fade hide" id="recharge_balance" tabindex="-1" role="dialog" aria-labelledby="myModalLabel" aria-hidden="true">

    <div class="modal-dialog">
        <div class="modal-content">
            <div class="modal-header">
                <button type="button" class="close" data-dismiss="modal" aria-hidden="true">&times;</button>
                <h3>调整余额</h3>
            </div>
            <div class="modal-body">
                <div class="modal-infp-style">
                    <table>
                        <tr>
                            <td>当前余额</td>
                            <td colspan='3' id="current_balance" class="input-common" ></td>
                        </tr>
                        <tr>
                            <td>调整金额</td>
                            <td colspan='3' id="time"><input type="number" id="balance" class="input-common" />增加或减少</td>
                        </tr>
                        <tr>
                            <td>备注</td>
                            <td colspan='3' id="time"><textarea id="remark_balance" class="input-common"></textarea></td>
                        </tr>
                    </table>
                </div>
            </div>

            <div class="modal-footer">
                <input type="hidden" id="balance_id" />
                <button class="btn btn-primary" onclick="addAccount(2)">保存</button>
                <button class="btn" data-dismiss="modal">关闭</button>
            </div>
        </div>
    </div>

</div>

<!-- 积分调整 -->
<div class="modal fade hide" id="recharge_point" tabindex="-1" role="dialog" aria-labelledby="myModalLabel" aria-hidden="true">

    <div class="modal-dialog">
        <div class="modal-content">
            <div class="modal-header">
                <button type="button" class="close" data-dismiss="modal" aria-hidden="true">&times;</button>
                <h3>调整积分</h3>
            </div>
            <div class="modal-body">
                <div class="modal-infp-style">
                    <table>
                        <tr>
                            <td>当前积分</td>
                            <td colspan='3' id="current_point" class="input-common"></td>
                        </tr>
                        <tr>
                            <td>调整积分</td>
                            <td colspan='3' id="time"><input type="number" id="point" class="input-common">增加或减少</td>
                        </tr>
                        <tr>
                            <td>备注</td>
                            <td colspan='3' id="time"><textarea id="remark_point" class="input-common"></textarea></td>
                        </tr>
                    </table>

                </div>
            </div>
            <div class="modal-footer">
                <input type="hidden" id="point_id" />
                <button class="btn btn-primary" onclick="addAccount(1)">保存</button>
                <button class="btn" data-dismiss="modal">关闭</button>
            </div>
        </div>
    </div>

</div>

<!-- 添加会员 -->
<div class="modal fade hide" id="add_user" tabindex="-1" role="dialog" aria-labelledby="myModalLabel" aria-hidden="true">

    <div class="modal-dialog">
        <div class="modal-content">
            <div class="modal-header">
                <button type="button" class="close" data-dismiss="modal" aria-hidden="true">&times;</button>
                <h3>添加会员</h3>
            </div>
            <div class="modal-body">
                <div class="modal-infp-style">
                    <table class="modal-tab">
                        <tr>
                            <td style="width:20%;"><span class="required">*</span>用户名</td>
                            <td colspan='3'>
                                <input type="text" id="username" class="input-common" />
                                <span id="usernameyz"></span>
                                <input type="hidden" value="不存在" id="isset_username" class="input-common" />
                            </td>
                        </tr>
                        <tr>
                            <td><span class="required">*</span>登录密码</td>
                            <td colspan='3'><input type="password" id="password" class="input-common"></td>
                        </tr>
                        <tr>
                            <td style="width:22%;">昵称</td>
                            <td colspan='3'>
                                <input type="text" id="nickname" class="input-common" />
                            </td>
                        </tr>
                        <tr>
                            <td>会员等级</td>
                            <td colspan='3'>
                                {if $level_list['data']}
                                <select id="member_level" class="select-common">
                                    {foreach name="level_list['data']" item="vo"}
                                    <option value="{$vo.level_id}">{$vo.level_name}</option>
                                    {/foreach}
                                </select>
                                {else/}
                                <span>暂无会员等级分类</span>
                                {/if}
                            </td>
                        </tr>
                        <tr>
                            <td>手机号码</td>
                            <td colspan='3'><input type="text" id="telephone" class="input-common"/></td>
                        </tr>
                        <tr>
                            <td>邮箱地址</td>
                            <td colspan='3'><input type="text" id="member_email" class="input-common" /></td>
                        </tr>
                        <tr>
                            <td>性别</td>
                            <td><label><input type="radio" checked="checked" name="sex" value="1"/>男&nbsp;&nbsp;</label><label><input name="sex" type="radio" value="2"/>女&nbsp;&nbsp;</label><label><input name="sex" type="radio" value="0"/>保密</label></td>
                        </tr>
                        <tr>
                            <td>账户状态</td>
                            <td><label><input type="radio" checked="checked" name="status" value="1"/>正常&nbsp;&nbsp;</label><label><input name="status" type="radio" value="0"/>锁定</label></td>
                        </tr>
                    </table>
                </div>
            </div>

            <div class="modal-footer">
                <button class="btn btn-primary" onclick="addUser()">保存</button>
                <button class="btn" data-dismiss="modal">关闭</button>
            </div>
        </div>
    </div>

</div>

<input type="hidden" id="modify_uid"/>
<!-- 修改会员 -->
<div class="modal fade hide" id="modify_user" tabindex="-1" role="dialog" aria-labelledby="myModalLabel" aria-hidden="true">

    <div class="modal-dialog" >
        <div class="modal-content">
            <div class="modal-header">
                <button type="button" class="close" data-dismiss="modal" aria-hidden="true">&times;</button>
                <h4 class="modal-title" id="myModalLabel">编辑会员</h4>
            </div>
            <div class="modal-body" style="min-height: 360px;">
                <div class="modal-infp-style">
                    <table class="modal-tab">
                        <tr style="height: 32px;">
                            <td style="width:20%"><span class="required">*</span>用户名</td>
                            <td colspan='3'>
                                <!-- 								<span id="modify_username"></span> -->
                                <input type="text" id="modify_username" class="input-common" />
                                <span id="modify_usernameyz"></span>
                                <input type="hidden" value="不存在" id="modify_isset_username"/>
                            </td>
                        </tr>
                        <tr>
                            <td style="width:20%">昵称</td>
                            <td colspan='3'><input type="text" id="modify_nickname"/></td>
                        </tr>
                        <tr>
                            <td>会员等级</td>
                            <td colspan='3' style="padding-bottom: 0;">
                                <p>
                                    {if $level_list['data']}
                                    <select id="modify_member_level">
                                        {foreach name="level_list['data']" item="vo"}
                                        <option value="{$vo.level_id}">{$vo.level_name}</option>
                                        {/foreach}
                                    </select>
                                    {else/}
                                    <span>暂无会员等级分类</span>
                                    {/if}
                                </p>
                            </td>
                        </tr>
                        <tr>
                            <td>手机号码</td>
                            <td colspan='3'><input type="text" id="modify_telephone" value=""/></td>
                        </tr>
                        <tr>
                            <td>邮箱地址</td>
                            <td colspan='3'><input type="text" id="modify_member_email"/></td>
                        </tr>
                        <tr>
                            <td>性别</td>
                            <td id="sex"><label><input type="radio" name="sex" value="1"/>男&nbsp;&nbsp;</label><label><input name="sex" type="radio" value="2"/>女&nbsp;&nbsp;</label><label><input name="sex" type="radio" value="0"/>保密</label></td>
                        </tr>
                        <tr>
                            <td>账户状态</td>
                            <td id="status"><label><input type="radio" name="status" value="1"/>正常&nbsp;&nbsp;</label><label><input name="status" type="radio" value="0"/>锁定</label></td>
                        </tr>
                    </table>
                </div>
            </div>

            <div class="modal-footer">
                <input type="hidden" id="modify_username_hidden" />
                <button class="btn btn-info" onclick="modifyUser()" id="butSubmit"  style="display:inline-block;">保存</button>
                <button type="button" class="btn btn-default" data-dismiss="modal">关闭</button>
            </div>
        </div>
    </div>

</div>

<!-- 修改会员密码 -->
<div class="modal fade hide" id="modify_password" tabindex="-1" role="dialog" aria-labelledby="myModalLabel" aria-hidden="true">

    <div class="modal-dialog">
        <div class="modal-content">
            <div class="modal-header">
                <button type="button" class="close" data-dismiss="modal" aria-hidden="true">&times;</button>
                <h4 class="modal-title" id="myModalLabel">重置密码</h4>
            </div>
            <div class="modal-body">
                <div class="modal-infp-style">
                    <table class="modal-tab">
                        <tr>
                            <td style="width:20%">密码</td>
                            <td colspan='3'><input type="text" id="modify_passwords" class="input-common"/></td>
                        </tr>
                    </table>
                </div>
            </div>

            <div class="modal-footer">
                <input type="hidden" id="modify_userid" />
                <button class="btn btn-primary" onclick="modifypassword()">保存</button>
                <button class="btn" data-dismiss="modal">关闭</button>
            </div>
        </div>
    </div>

</div>
{/block}
{block name="script"}
<script type="text/javascript">
    function LoadingInfo(page_index) {
        var search_text = $("#search_text").val();
        var levelid = $("#level_name").val();
        $.ajax({
            type : "post",
            url : "{:__URL('ADMIN_MAIN/member/memberlist')}",
            data : {
                "page_index" : page_index, "page_size" : $("#showNumber").val(), "search_text" : search_text,"levelid":levelid
            },
            success : function(data) {
                var html = '';
                if (data["data"].length > 0) {
                    for (var i = 0; i < data["data"].length; i++) {
                        html += '<tr align="center">';
                        html += '<td><input name="sub" type="checkbox" value="'+ data["data"][i]["uid"]+'" ></td>';
                        html += '<td align="left">';

                        if(data["data"][i]["user_headimg"] ==""){
                            html += '<img src="{:__IMG($default_headimg)}" class="head-portrait" />';
                            html += '<div style="float:left;">';
                            if(data["data"][i]["user_name"] == '' || data["data"][i]["user_name"] == null){
// 							html+='用户名:'+'--'+'<br/>';
                                html += '<label style="float:none;width:100%">用户名：<span>--</span></label>';
                            }else{
// 							html+='用户名:'+data["data"][i]["user_name"] +'<br/>';
                                html += '<label style="float:none;width:100%">用户名：<span>' + data["data"][i]["user_name"] + '</span></label>';
                            }
                            if (data["data"][i]["user_tel"] == null || "" == data["data"][i]["user_tel"]) {
                                if (data["data"][i]["user_email"] == null || "" == data["data"][i]["user_email"]) {
// 								html += '昵称 : '+data["data"][i]["nick_name"] +'<br/>'+'手机 :'+'--'+'<br/>'+'邮箱 : '+'--';
                                    html += '<label style="float:none;width:100%">昵称: <span>' + data["data"][i]["nick_name"] + '</span></label>';
                                    html += '<label style="float:none;width:100%"><span>手机：--</span></label>';
                                    html += '<label style="float:none;width:100%"><span>邮箱：--</span></label>';
                                } else {
// 								html += '昵称 : '+data["data"][i]["nick_name"] +'<br/>'+'手机 : '+'--'+'<br/>'+'邮箱 : '+data["data"][i]["user_email"];
                                    html += '<label style="float:none;width:100%">昵称 :<span>' + data["data"][i]["nick_name"] + '</span></label>';
                                    html += '<label style="float:none;width:100%"><span>手机：--</span></label>';
                                    html += '<label style="float:none;width:100%"><span>邮箱：' + data["data"][i]["user_email"] + "</span></label>";
                                }
                            } else {
                                if (data["data"][i]["user_email"] == null || "" == data["data"][i]["user_email"]) {
// 								html += '昵称 : '+data["data"][i]["nick_name"] +'<br/>'+'手机 : '+data["data"][i]["user_tel"]+'<br/>'+'邮箱 : '+'--';
                                    html += '<label style="float:none;width:100%">昵称：<span>' + data["data"][i]["nick_name"] + "</span></label>";
                                    html += '<label style="float:none;width:100%">手机：<span>' + data["data"][i]["user_tel"] + "</span></label>";
                                    html += '<label style="float:none;width:100%">邮箱：<span>--</span></label>';
                                } else {
// 								html += '昵称 : '+data["data"][i]["nick_name"] +'<br/>'+'手机 : '+data["data"][i]["user_tel"]+'<br/>'+'邮箱 : '+data["data"][i]["user_email"];
                                    html += '<label style="float:none;width:100%">昵称：<span>' + data["data"][i]["nick_name"] + '</span></label>';
                                    html += '<label style="float:none;width:100%">手机：<span>' + data["data"][i]["user_tel"] + '</span></label>';
                                    html += '<label style="float:none;width:100%">邮箱：<span>' + data["data"][i]["user_email"] + "</span></label>";
                                }
                            }
                        }else{
                            html += '<img src="'+__IMG(data["data"][i]["user_headimg"])+'" class="head-portrait" />';
                            if (data["data"][i]["user_tel"] == null || "" == data["data"][i]["user_tel"]) {
                                if (data["data"][i]["user_email"] == null || "" == data["data"][i]["user_email"]) {
// 								html += '昵称 : '+data["data"][i]["nick_name"] +'<br/>'+'手机 : '+'--'+'<br/>'+'邮箱 : '+'--';
                                    html += '<label style="float:none;width:100%">昵称：<span>' + data["data"][i]["nick_name"] + '</span></label>';
                                    html += '<label style="float:none;width:100%">手机：<span>--</span></label>';
                                    html += '<label style="float:none;width:100%">邮箱：<span>--</span></label>';
                                } else {
// 								html += '昵称 : '+data["data"][i]["nick_name"] +'<br/>'+'手机 : '+'--'+'<br/>'+'邮箱 : '+data["data"][i]["user_email"];
                                    html += '<label style="float:none;width:100%">昵称：<span>' + data["data"][i]["nick_name"] + '</span></label>';
                                    html += '<label style="float:none;width:100%">手机：<span>--</span></label>';
                                    html += '<label style="float:none;width:100%">邮箱：<span>' + data["data"][i]["user_email"] + '</span></label>';
                                }
                            } else {
                                if (data["data"][i]["user_email"] == null || "" == data["data"][i]["user_email"]) {
// 								html += '昵称 : '+data["data"][i]["nick_name"] +'<br/>'+'手机 : '+data["data"][i]["user_tel"]+'<br/>'+'邮箱 : '+'--';
                                    html += '<label style="float:none;width:100%">昵称：<span>' + data["data"][i]["nick_name"] + '</span></label>';
                                    html += '<label style="float:none;width:100%">手机：<span>' + data["data"][i]["user_tel"] + '</span></label>';
                                    html += '<label style="float:none;width:100%">邮箱：<span>--</span></label>';
                                } else {
// 								html += '昵称 : '+data["data"][i]["nick_name"] +'<br/>'+'手机 : '+data["data"][i]["user_tel"]+'<br/>'+'邮箱 : '+data["data"][i]["user_email"];
                                    html += '<label style="float:none;width:100%">昵称：<span>' + data["data"][i]["nick_name"] + '</span></label>';
                                    html += '<label style="float:none;width:100%">手机：<span>' + data["data"][i]["user_tel"] + '</span></label>';
                                    html += '<label style="float:none;width:100%">邮箱：<span>' + data["data"][i]["user_email"] + '</span></label>';
                                }
                            }
                        }
                        html += '</div>';
                        html += '</td>';
                        if(data["data"][i]["level_name"]==null || data["data"][i]["level_name"]==undefined){
                            html += '<td>--</td>';
                        }else{
                            html += '<td>' + data["data"][i]["level_name"] + '</td>';
                        }
                        html += '<td>' + data["data"][i]["point"] + '</td>';
                        html += '<td>'+'¥'+ data["data"][i]["balance"] +'</td>';
                        html += '<td>' +'注册时间 : '+ timeStampTurnTime(data["data"][i]["reg_time"]) +'<br>'+'最后登录 : '+ timeStampTurnTime(data["data"][i]["current_login_time"])+'</td>';
                        html += data["data"][i]["user_status"] == 0 ? '<td style="color:red;">锁定</td>' : '<td style="color:green;">正常</td>';
                        html += '<td><a style="display: none" href="'+__URL('ADMIN_MAIN/member/pointdetail?member_id='+ data['data'][i]['uid'])+'">积分明细</a>&nbsp;&nbsp;';
                        html += '<a style="display: none" href="'+__URL('ADMIN_MAIN/member/accountdetail?member_id='+ data['data'][i]['uid'])+'">余额明细</a><br/>';
                        html += '<a onclick="recharge_point('+ data["data"][i]["uid"]+','+ data["data"][i]["point"] +')">积分调整</a>&nbsp;&nbsp;';
                        html += '<a onclick="recharge_balance('+ data["data"][i]["uid"]+','+data["data"][i]["balance"]+')">余额调整</a><br/>';

                        if(data["data"][i]["is_system"] != 1){
                            if(data["data"][i]["user_status"] == 0){
                                html += '<a onclick="unlockuser('+ data["data"][i]["uid"]+')">设置解锁&nbsp;&nbsp;&nbsp;</a>';
                            }else{
                                html += '<a onclick="lockuser('+ data["data"][i]["uid"]+')">设置锁定&nbsp;&nbsp;&nbsp;</a>';
                            }
                            html += '<a onclick="modify_password('+ data["data"][i]["uid"]+')">重置密码</a><br/>';

                            html += '<a onclick="modify_user('+ data["data"][i]["uid"]+')">修改</a>&nbsp;&nbsp;<a onclick="delete_user('+ data["data"][i]["uid"]+')">删除</a><br/>';

                        }
                        html += '</td>'
                        html += '</tr>';
                    }
                } else {
                    html += '<tr align="center"><td colspan="9">暂无符合条件的数据记录</td></tr>';
                }
                $(".table-class tbody").html(html);
                initPageData(data["page_count"],data['data'].length,data['total_count']);
                $("#pageNumber").html(pagenumShow(jumpNumber,$("#page_count").val(),{$pageshow}));
            }
        });
    }

    //全选
    function CheckAll(event){
        var checked = event.checked;
        $(".table-class tbody input[type = 'checkbox']").prop("checked",checked);
    }

    function searchData(){
        LoadingInfo(1);
    }

    //锁定会员
    function lockuser(uid){
        $.ajax({
            type : "post",
            url : "{:__URL('ADMIN_MAIN/member/memberlock')}",
            data : { "id" : uid },
            success : function(data) {
                if (data["code"] > 0) {
                    LoadingInfo(getCurrentIndex(uid,'#productTbody'));
                    showTip(data['message'],'success');
                }else{
                    showTip(data['message'],'error');
                }
            }
        });
    }

    //解锁会员
    function unlockuser(uid){
        $.ajax({
            type : "post",
            url : "{:__URL('ADMIN_MAIN/member/memberunlock')}",
            data : { "id" : uid },
            success : function(data) {
                if (data["code"] > 0) {
                    LoadingInfo(getCurrentIndex(uid,'#productTbody'));
                    showTip(data['message'],'success');
                }else{
                    showTip(data['message'],'error');
                }
            }
        });
    }

    //添加会员弹出
    function add_user(){
        $("#add_user").modal("show");
    }

    //积分充值
    function recharge_point(uid,point){
        $("#recharge_point").modal("show");
        $("#point_id").val(uid);
        $("#current_point").text(point);
    }
    //余额充值
    function recharge_balance(uid,balance){
        $("#recharge_balance").modal("show");
        $("#balance_id").val(uid);
        $("#current_balance").text(balance);
    }

    //充值
    function addAccount(type){
        var curr_obj = "";
        if(type == 1){
            var id = $("#point_id").val();
            var num = $("#point").val();
            var current_point = $("#current_point").text();
            var point = (parseInt(current_point) + parseInt(num));
            if(num == ''){
                showTip('积分不能为空','warning');
                return false;
            }
            var text = $("#remark_point").val();
            if(parseInt(point) < 0){
                showTip('积分不能为负数','warning');
                return false;
            }
            curr_obj = "recharge_point";
        }else{
            var id = $("#balance_id").val();
            var num = $("#balance").val();
            var current_balance = $("#current_balance").text();
            var balance = (parseInt(current_balance) + parseInt(num));
            if(num == ''){
                showTip('余额不能为空','warning');
                return false;
            }
            var text = $("#remark_balance").val();
            if(parseInt(balance) < 0){
                showTip('余额不能为负数','warning');
                return false;
            }
            curr_obj = "recharge_balance";
        }
        $.ajax({
            type : "post",
            url : "{:__URL('ADMIN_MAIN/member/addmemberaccount')}",
            data : {
                "id" : id,
                "type" : type,
                "num" : num,
                "text" : text
            },
            success : function(data) {
                if (data["code"] > 0) {
                    LoadingInfo(getCurrentIndex(id,'#productTbody'));
                    showTip(data['message'],'success');
                    $("#"+curr_obj).modal("hide");
                }else{
                    showTip(data['message'],'error');
                }
            }
        });
    }

    //检测输入的会员用户名是否已经存在
    $("#username").blur(function(){
        var username = $(this).val();
        $(this).css("border","1px solid #ccc");
        $("#usernameyz").css("color","black").text("");
        $("#isset_username").attr("value","不存在");
        if(username === $("#modify_username_hidden").val()){
            return;
        }
        checkUserName(username);
    });

    function checkUserName(username){
        var flag = true;
        $.ajax({
            type: "GET",
            url: "{:__URL('ADMIN_MAIN/member/check_username')}",
            async : false,
            data: {"username":username},
            success: function(data){
                if(data){
                    flag = false;
                    $("#username").css("border","1px solid red");
                    $("#usernameyz").css("color","red").text("用户名已存在");
                    $("#isset_username").attr("value","存在");
                }
            }
        });
        return flag;
    }

    //添加会员
    function addUser(){
        var username = $("#username").val();
        var nickname = $("#nickname").val();
        var password = $("#password").val();
        var level_name = $("#member_level").val();
        var tel = $("#telephone").val();
        var email = $("#member_email").val();
        var sex = $("input[name='sex']:checked").val();
        var status = $("input[name='status']:checked").val();

        if (username == '') {
            showTip('用户名不能为空','warning');
            return;
        }

        if(!checkUserName(username)){
            showTip('用户名已存在','warning');
            return;
        }

        if (password == null || password.length < 6) {
            showTip('密码必须不小于6位！','warning');
            return;
        }
        if(tel.length > 0){
            if(!(/^1(3|4|5|7|8)\d{9}$/.test(tel))){
                showTip("手机号码有误，请重填",'warning');
                return;
            }
        }
        if(email.length > 0){
            if(!(/^(\w-*\.*)+@(\w-?)+(\.\w{2,})+$/.test(email))){
                showTip('邮箱错误,请重填','warning');
                return;
            }
        }
        $.ajax({
            type : "post",
            url : __URL("ADMIN_MAIN/member/addmember"),
            data : {
                'username' : username,
                'nickname' :nickname,
                'password' : password,
                'level_name' : level_name,
                'tel' : tel,
                'email' : email,
                'sex' : sex,
                'status' : status
            },
            success : function(data) {
                if (data['code'] > 0) {
                    showTip(data['message'],'success');
                    $("#add_user").modal("hide");
                    LoadingInfo(getCurrentIndex(1,'#productTbody'));
                } else {
                    showTip(data['message'],'error');
                    flag = false;
                }
            }
        });
    }
    //修改会员弹出
    function modify_user(uid){
        var id = parseInt(uid);
        $("#modify_user").modal("show");
        $.ajax({
            type : "post",
            url : "{:__URL('ADMIN_MAIN/member/getmemberdetail')}",
            data : { 'uid':id, },
            success : function(data) {
                //alert(JSON.stringify(data['user_name']));
                $("#modify_uid").val(data.uid);
                if(data['user_name']!=''){
                    $("#modify_username").val(data.user_name);
                    $("#modify_username").attr('disabled',true);
                }

                $("#modify_nickname").val(data.nick_name);
                //$("#modify_password").val(data.user_password);
                $("#modify_username_hidden").val(data.user_name);
                $("#modify_telephone").val(data.user_tel);
                $("#modify_member_email").val(data.user_email);
                $("#modify_member_level").find("option[value="+data.member.member_level+"]").attr("selected",true);
                $("#sex").find("input[value="+data.sex+"]").attr("checked",true);
                $("#status").find("input[value="+data.user_status+"]").attr("checked",true);
            }
        });
    }

    //重置密码弹出
    function modify_password(uid){
        $("#modify_password").modal("show");
        $("#modify_userid").val(uid);
    }

    //修改密码提交
    function modifypassword(){
        var uid = $("#modify_userid").val();
        var password = $("#modify_passwords").val();
        if (password == null || password.length < 6) {
            showTip('密码必须不小于6位！','warning');
            return false;
        }
        $.ajax({
            type : "post",
            url : "{:__URL('ADMIN_MAIN/member/updatememberpassword')}",
            data : {
                'uid':uid,
                'user_password' :password
            },
            success : function(data) {
                if (data['code'] > 0) {
                    showTip('修改成功','success');
                    LoadingInfo(getCurrentIndex(uid,'#productTbody'));
                    $("#modify_password").modal("hide");
                } else {
                    showTip('修改失败','error');
                    flag = false;
                }
            }
        });
    }

    function delete_user(uid){
        $( "#dialog" ).dialog({
            buttons: {
                "确定": function() {
                    $.ajax({
                        type : "post",
                        url : "{:__URL('ADMIN_MAIN/member/deletemember')}",
                        data : { "uid" : uid.toString() },
                        dataType : "json",
                        success : function(data) {
                            if(data["code"] > 0 ){
                                LoadingInfo(getCurrentIndex(uid.toString(),'#productTbody'));
                                showTip(data["message"],'success');
                                $("#chek_all").prop("checked", false);
                            }else{
                                showTip(data["message"],'error');
                            }
                        }
                    });
                    $(this).dialog('close');
                },
                "取消,#e57373": function() {
                    $(this).dialog('close');
                },
            },
            contentText:"删除会员同时会删除会员相关账户信息，确定要删除吗？",
        });
    }

    ////修改会员
    function modifyUser(){
        var uid = $("#modify_uid").val();
        var username = $("#modify_username").val();
        var nickname = $("#modify_nickname").val();
        var tel = $("#modify_telephone").val();
        var email = $("#modify_member_email").val();
        var level_name = $("#modify_member_level").val();
        var sex = $("input[name='sex']:checked").val();
        var status = $("input[name='status']:checked").val();

        if(tel.length > 0){
            if(!(/^1(3|4|5|7|8)\d{9}$/.test(tel))){
                showTip("手机号码有误，请重填",'warning');
                return false;
            }
        }
        if(email.length > 0){
            if(!(/^(\w-*\.*)+@(\w-?)+(\.\w{2,})+$/.test(email))){
                showTip('邮箱错误,请重填','warning');
                return false;
            }
        }
        $.ajax({
            type : "post",
            url : "{:__URL('ADMIN_MAIN/member/updatemember')}",
            data : {
                'uid':uid,
                'user_name' :username,
                'nick_name' : nickname,
                'level_name' : level_name,
                'tel' : tel,
                'email' : email,
                'sex' : sex,
                'status' : status
            },
            success : function(data) {
                if (data['code'] > 0) {
                    showTip(data['message'],'success');
                    LoadingInfo(getCurrentIndex(uid,'#productTbody'));
                    $("#modify_user").modal("hide");
                } else {
                    showTip(data['message'],'error');
                    flag = false;
                }
            }
        });
    }
    //批量删除
    function batchDelete() {
        var uid= new Array();
        $("#productTbody input[type='checkbox']:checked").each(function() {
            if (!isNaN($(this).val())) {
                uid.push($(this).val());
            }
        });
        if(uid.length ==0){
            $( "#dialog" ).dialog({
                buttons: {
                    "确定,#e57373": function() {
                        $(this).dialog('close');
                    }
                },
                contentText:"请选择需要操作的记录",
                title:"消息提醒",
            });
            return false;
        }
        delete_user(uid);
    }

    /**
     * 会员数据导出
     */
    function dataExcel(){
        var search_text = $("#search_text").val();
        var levelid = $("#level_name").val();
        window.location.href=__URL("ADMIN_MAIN/member/memberDataExcel?search_text="+search_text+"&levelid="+levelid);
    }
</script>
{/block}